home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / emacssrc.zip / EMACSSRC.TAR / emacs-19.17 / lib-src / test-distrib.c < prev    next >
C/C++ Source or Header  |  1993-08-12  |  2KB  |  73 lines

  1. #include <stdio.h>
  2. #ifdef WINDOWSNT
  3. #include <io.h>
  4. #endif /* WINDOWSNT */
  5.  
  6. /* Break string in two parts to avoid buggy C compilers that ignore characters
  7.    after nulls in strings.  */
  8.  
  9. char string1[] = "Testing distribution of nonprinting chars:\n\
  10. Should be 0177: \177 Should be 0377: \377 Should be 0212: \212.\n\
  11. Should be 0000: ";
  12.  
  13. char string2[] = ".\n\
  14. This file is read by the `test-distribution' program.\n\
  15. If you change it, you will make that program fail.\n";
  16.  
  17. char buf[300];
  18.   
  19. /* Like `read' but keeps trying until it gets SIZE bytes or reaches eof.  */
  20. int
  21. cool_read (fd, buf, size)
  22.      int fd;
  23.      char *buf;
  24.      int size;
  25. {
  26.   int num, sofar = 0;
  27.  
  28.   while (1)
  29.     {
  30.       if ((num = read (fd, buf + sofar, size - sofar)) == 0)
  31.     return sofar;
  32.       else if (num < 0)
  33.     return num;
  34.       sofar += num;
  35.     }
  36. }
  37.  
  38. main (argc, argv)
  39.      int argc;
  40.      char **argv;
  41. {
  42.   int fd;
  43.  
  44.   if (argc != 2)
  45.     {
  46.       fprintf (stderr, "Usage: %s testfile\n", argv[0]);
  47.       exit (2);
  48.     }
  49.   fd = open (argv[1], 0);
  50.   if (fd < 0)
  51.     {
  52.       perror (argv[1]);
  53.       exit (2);
  54.     }
  55.   if (cool_read (fd, buf, sizeof string1) != sizeof string1 ||
  56.       strcmp (buf, string1) ||
  57.       cool_read (fd, buf, sizeof string2) != sizeof string2 - 1 ||
  58.       strncmp (buf, string2, sizeof string2 - 1))
  59.     {
  60.       fprintf (stderr, "Data in file `%s' has been damaged.\n\
  61. Most likely this means that many nonprinting characters\n\
  62. have been corrupted in the files of Emacs, and it will not work.\n",
  63.            argv[1]);
  64.       exit (2);
  65.     }
  66.   close (fd);
  67. #ifdef VMS
  68.   exit (1);            /* On VMS, success is 1.  */
  69. #else
  70.   exit (0);
  71. #endif
  72. }
  73.